package com.fengpb.friday.conductor.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonClientConfig {

    @Autowired
    private ServerConfig serverConfig;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        String hostPort = serverConfig.getHostPorts().get(0);
        config.useSingleServer()
                .setAddress("redis://" + hostPort)
                .setPassword(serverConfig.getPassword())
                .setPingConnectionInterval(2000);
        config.setUseScriptCache(true);
        return Redisson.create(config);
    }
    
}
